﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using JTG.ServiceInterface;
using Tzw.Common;

namespace JTG.CheckInMachine
{
    public partial class Main : BaseForm
    {
        private int _managerCloseTime = 5;//管理员键盘自动关闭时间
        public Main()
        {
            InitializeComponent();

            //关闭按钮事件
            CloseEvent += (s, e) => { panel1.Visible = true; };
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            lab_time.Text = DateTime.Now.ToString("HH:mm:ss");
            if (panel1.Visible && _managerCloseTime > 0)
            {
                _managerCloseTime--;
                lab_CloseTips.Text = $"{_managerCloseTime}秒后自动关闭";
            }
            else
            {
                panel1.Visible = false;
                _managerCloseTime = 5;
            }
        }

        private void btn_qrcode_Click(object sender, EventArgs e)
        {
            new ReadCard(CheckInType.ElectronicCard).Show();
        }

        private void btn_card_Click(object sender, EventArgs e)
        {
            new ReadCard(CheckInType.Card).Show();
        }

        private void btn_wx_Click(object sender, EventArgs e)
        {
            new ReadCard(CheckInType.WxQrCode).Show();
        }

        #region 关闭窗口密码输入框

        private void btn_ClearPwd_Click(object sender, EventArgs e)
        {
            txt_pwd.Text = "";
        }

        private void btn_DelPwd_Click(object sender, EventArgs e)
        {
            if (btn_DelPwd.Text == "关闭")
                panel1.Visible = false;

            if (txt_pwd.Text.Length > 0)
                txt_pwd.Text = txt_pwd.Text.Substring(0, txt_pwd.Text.Length - 1);

            if (txt_pwd.Text.Length == 0)
                btn_DelPwd.Text = "关闭";
        }

        private void btn_NumClick(object sender, EventArgs e)
        {
            txt_pwd.Text += ((Button)sender).Text;
            btn_DelPwd.Text = "删除";

            if (txt_pwd.Text == "666666")
                Close();
        }

        #endregion
    }
}
